<!DOCTYPE HTML>
<html>
<head>
    <include file="Common:header_include"/>
    <title>编辑患者化验记录</title>
    <style>
        #img{
            /*margin-left: 80px;*/
        }
        #img img{
            width: 200px;
            height: 200px;
            float: left;
            margin-left: 15px ;
            border-radius: 10%;
        }
        /*.img img{*/
            /*width: 180px;*/
            /*border-radius: 5px;*/
            /*margin-bottom: 10px;*/
            /*margin-right: 10px;*/
        /*}*/
    </style>
</head>
<body>
<div class="pd-20">
    <form action="{:U('edit')}" method="post" class="form form-horizontal" id="form">
        <div class="row cl">
            <input name="id" value="{$data['inspection_content'][0]['id']}" hidden="hidden">
            <label class="form-label col-2"><span class="c-red">*</span>患者姓名：</label>
            <div class="formControls col-7">
                <span class="select-box">
                <select class="select Validform_error" size="1" datatype="*" name="userid" nullmsg="请选择">
                    <option value="" selected="" disabled="disabled">请选择</option>
                    <volist name=":getpatientList(1)" id="v">
                        <option value="{$v.id}" <if condition="$data['patient_info']['id'] eq $v['id']">selected</if> >{$v.realname}</option>
                    </volist>
                </select>
                </span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-2"><span class="c-red">*</span>检查单所属医院：</label>
            <div class="formControls col-7">
                <span class="select-box">
                <select class="select Validform_error" size="1" name="hospitalid" datatype="*" nullmsg="请选择">
                     <option value="" selected="" disabled="disabled">请选择</option>
                    <option value="-1"   <if condition="$data.hospitalid eq -1">selected</if>>通用型检查单</option>
                    <option value="-2"  <if condition="$data.hospitalid eq -2">selected</if>>默认检查单</option>
                    <volist name=":getLists(hospitalinfo)" id="v">
                          <option value="{$v['id']}" <if condition="$data.hospitalid eq $v['id']">selected</if>>{$v['name']}</option>
                    </volist>
                </select>
                </span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-2"><span class="c-red"></span>上传时间：</label>
            <div class="formControls col-7">
                <input type="text" class="input-text" placeholder="请输入" name="uploadtime" value="{$data['uploadtime']}">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-2"><span class="c-red"></span>检查时间：</label>
            <div class="formControls col-7">
                <input type="text" class="input-text" placeholder="请输入"  name="testtime" value="{$data['testtime']}">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-2" style="margin-top: 15px"><span>化验单化验项目：</span></label>
            <div class="formControls col-10">
                <div class="row" >
                    <div class="col-4">
                        <select class="select Validform_error" size="1" name="indexid" datatype="*"  nullmsg="请选择" onchange="getitrmifolist()"  id="mySelect">
                            <option value="" selected="" disabled="disabled">请选择</option>
                            <volist name="groupid" id="v">
                                <option value="{$v.testid}" <if condition="$groupid[key] eq 0">selected</if>>{:getInspectioninfo($v['testid'])}</option>
                            </volist>
                        </select>
                    </div>
                    <div class="col-7"></div>
                    <br>
                    <div class="row">
                        <div class="col-4" >
                            <table class="table table-border table-bordered">
                                <tr class="text-c">
                                    <td style="width: 180px">化验项</td>
                                    <td>参考值</td>
                                    <td>备用值</td>
                                    <td>操作</td>
                                </tr>
                            </table>
                            <table class="table table-border table-bordered" id="apend" >
                            </table>
                        </div>
                        <div id="layer-photos-demo" class="layer-photos-demo">
                            <div class="col-7 img" style="margin-left: 20px" id="imges">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row cl">
            <div class="col-10 col-offset-2">
                <input class="btn btn-primary radius" type="submit" value="提交">
            </div>
        </div>
    </form>
</div>
<include file="Common:footer_include"/>
<script>
    function entering($id){
        var jqeryobj = new Object();
        jqeryobj.id           =   $id;
        jqeryobj.itemvalue     =   $("#itemvalue"+$id).val();
        jqeryobj.paramvalue  =   $("#paramvalue"+$id).val();
        var ajaxurl="{:U('InspectionContent/editcontent')}";
        $.ajax({
            url:ajaxurl ,
            type: 'post',
            data:jqeryobj,
            async: true,
            enctype: 'multipart/form-data',
            success: function (data) {
                if(data.status==1){
                    layer.msg('录入成功', {
                        icon: 1,
                        time: 1000 //1秒关闭（如果不配置，默认是3秒）
                    }, function(){
//                        top.location.reload();
                    });
                }else{
                    layer.msg('录入失败', {icon: 5});
                }
            }
        });
    }

//    layer.photos({
//        photos: '#layer-photos-demo',
//        tab: function(pic, layero){
//            console.log(pic) //当前图片的一些信息
//        }
//    });
    layer.photos({
        photos: '#layer-photos-demo'
    });
    /**
     * 根据化验单获取化验项
     * @param $indexid
     */
    getitrmifolist();
    function getitrmifolist () {
        $testid=$("#mySelect option:selected").val();
        if($testid==""){
            $testid = {$groupid[0]['testid']};
        }
        var jqobj = new Object();
        jqobj.indexid = {$data['id']};
        jqobj.testid = $testid;
        var ajaxurl = "{:U('InspectionIndex/getiteminfolist')}";
        var apend = $('#apend');
             apend.html("");
        $.ajax({
            url:ajaxurl ,
            type: 'post',
            data:jqobj,
            async: true,
            enctype: 'multipart/form-data',
            success:function (data) {
                $.each(data, function (i, items) {
                    $("#apend").append('<tr class="text-c"> ' +
                        '<td  style="width: 180px">'+items.inspectioniteminfo.name+'</td> ' +
                        '<td><input type="text" id="itemvalue'+items.id+'" class="input-text" value="'+items.itemvalue+'"></td>' +
                        '<td><input type="text" id="paramvalue'+items.id+'" class="input-text" value="'+items.paramvalue+'"></td>' +
                        '<td><input type="button" <if condition="'+items.itemvalue+' eq 0">class="btn btn-danger radius"<else/>class="btn btn-secondary radius"</if> <if condition="'+items.itemvalue+'">value="修改"<else/>value="录入"</if> onclick="entering('+items.id+')"></td>' +
                        '</tr>' +
                        '');
                });
                getimgs();
            }
        })
    }
    /***
     * 获取相对应检查单的图片
     */
    function  getimgs() {
        $testid=$("#mySelect option:selected").val();
        if($testid==""){
            $testid = {$groupid[0]['testid']};
        }
        var jqobj = new Object();
        jqobj.indexid = {$data['id']};
        jqobj.testid = $testid;
        var ajaxurl = "{:U('InspectionIndex/getimgs')}";
        var imges = $('#imges');
        imges.html("");
        $.ajax({
            url:ajaxurl ,
            type: 'post',
            data:jqobj,
            async: true,
            enctype: 'multipart/form-data',
            success:function (data) {
                $.each(data, function (i, items) {
                    $("#imges").append('<img src="__UPS__'+items.cover+'"  width="100" height="100" alt="'+items.description+'">');
                });
            }
        })

    }
</script>
</body>
</html>